package leetcode.code0350;

import leetcode.IDebug;

public class Solution implements IDebug {

	public int[] intersect(int[] nums1, int[] nums2) {
		int[] h1 = new int[1001];
		int[] h2 = new int[1001];
		for (int num : nums1) {
			h1[num]++;
		}
		for (int num : nums2) {
			h2[num]++;
		}
		int size = 0;
		for (int i = 0; i < h1.length; i++) {
			int min = Math.min(h1[i], h2[i]);
			size += min;
			h1[i] = min;
		}
		int[] ans = new int[size];
		int p = 0;
		for (int i = 0; i < h1.length; i++) {
			int cur = h1[i];
			while (cur > 0) {
				ans[p++] = i;
				cur--;
			}
		}
		return ans;
	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
